package org.winexpress

import grails.converters.JSON
import org.codehaus.groovy.grails.web.json.JSONObject
import org.codehaus.groovy.grails.web.json.JSONArray

class LogoutController {
    // shared methods
    def sendResponse(statusCode) {
        if (statusCode == 404) {
            JSONObject o = new JSONObject()
            o.put(statusCode, true)
            render o as JSON
        }
        
        response.status = statusCode
        render response
        
        // 200-OK (e.g. GET success)
        // 201-Created (e.g. POST success)
        // 403-Forbidden (e.g. LOGIN failure)
        // 400-Bad Request (e.g. PUT,POST,DELETE failure)
        // 404-Not Found (e.g. GET failure)
        // 500-Internal Server Error (other...)
    }
    
    

    // REST operations
    // GET
    def show = {
       
        // println 'LogoutController >> Show >> START'
        
        CustomerManagement cman = new CustomerManagement()
        
        if (params.username) {
            def c = cman.getCustomerByUsername(params.username)
            if (c.activationStatus == true) {
                render c as JSON
                sendResponse(200)
            }
            else {
                sendResponse(404)
            }
            
            println 'Show logout by USERNAME >> ' + c.id + " " + c
        }
        
        // println 'LogoutController >> Show >> END'
        
    }
    
    // PUT
    
    
    // DELETE
    
    
    // POST
    
    
}
